package com.books.dao;

import com.books.model.entity.question.Answer;
import com.books.model.entity.question.NewQuestion;
import com.books.model.entity.question.Question;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author 饿熊的咆哮
 * @Date 2021/11/2 13:57
 * @Version 1.0
 */
@Component
public class NewQuestionDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    public void addNewQuestion(NewQuestion newQuestion){
        mongoTemplate.save(newQuestion);
    }

    public List<NewQuestion> findNewQuestionByPeopleId(Integer peopleId){
        Query query = new Query(Criteria.where("peopleId").is(peopleId));
        List<NewQuestion> newQuestions = mongoTemplate.find(query, NewQuestion.class);
        return newQuestions;
    }

    public void delById(String _id){
        Query query=new Query(Criteria.where("_id").is(_id));
        mongoTemplate.remove(query, NewQuestion.class);
    }
}
